package com.myr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.myr.dao.UsersDao;
import com.myr.entity.Users;
import com.myr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author myr
 * @version 1.0
 * @date 2022/11/19 15:33
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UsersDao usersDao;

    @Override
    public Page<Users> selectAll(Integer pageNum, Integer pageSize) {
        Page<Users> page = new Page<>(pageNum, pageSize);
        Page<Users> usersPage = usersDao.selectPage(page, null);
        return usersPage;
    }

    @Override
    public int insert(Users users) {
        int insert = usersDao.insert(users);
        return insert;
    }

    @Override
    public int update(Users users) {
        int i = usersDao.updateById(users);
        return i;
    }

    @Override
    public int delete(Integer id) {
        int i = usersDao.deleteById(id);
        return i;
    }

    @Override
    public Users login(String userName, String password) {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.eq("userName", userName);
        wrapper.eq("password", password);
        Users users = usersDao.selectOne(wrapper);
        return users;
    }


}
